import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import IndexGoods from './components/IndexGoods/IndexGoods'
import Banner from './components/Banner/Banner'
import GetNew from './components/GetNew/GetNew';
import { reqgetbanner, reqgetindexgoods, reqgetnew } from "../../http/api";

export default class Home extends Component {
    constructor(){
        super()
        this.state={
          getnew:[],
          banner:[],
          indexgoods:[],
          n:0
        }
       
    }
    componentDidMount(){
      this.getnew()
      this.getbanner()
      this.getindexgoods()
    }
//请求新人专享
async getnew() {
  let res = await reqgetnew();
  if (res.data.code === 200) {
    this.setState({
      getnew: res.data.list,
    });
  }
}
    
    //请求轮播
  async getbanner() {
    let res = await reqgetbanner();
    if (res.data.code === 200) {
      this.setState({
        banner: res.data.list,
      });
    }
  }
  //请求商品信息
  async getindexgoods() {
    let res = await reqgetindexgoods();
    if (res.data.code === 200) {
      this.setState({
        indexgoods: res.data.list,
      });
    }
  }
  render() {
    let { indexgoods,banner,getnew,n} = this.state;

    return (
      <div>
        <Header title='首页'></Header>
        {/* 新人 */}
        <GetNew getnew={getnew}></GetNew>
        {/* 轮播 */}
        <Banner banner={banner}></Banner>
         {/* 商品信息 */}
        <IndexGoods indexgoods={indexgoods} n={n} changeN={(n)=>{
          this.setState({
            n
          })
        }}></IndexGoods>
      </div>
    )
  }
}
